package com.guigu.ssyx.product.service.impl;

import com.atguigu.ssyx.vo.product.CategoryQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.guigu.ssyx.product.entity.Category;
import com.guigu.ssyx.product.mapper.CategoryMapper;
import com.guigu.ssyx.product.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 商品三级分类 服务实现类
 * </p>
 *
 * @author liuyang
 * @since 2025-09-10
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public IPage<Category> selectPageCategory(IPage<Category> categoryPage, CategoryQueryVo categoryQueryVo) {
        String name = categoryQueryVo.getName();
        LambdaQueryWrapper<Category> categoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(name)){
            categoryLambdaQueryWrapper.like(Category::getName,name);
        }

        IPage<Category> categoryIPage = categoryMapper.selectPage(categoryPage, categoryLambdaQueryWrapper);

        return categoryIPage;
    }
}
